<?php
/**
 * @package flickrSync
 * @version 1.0
 */
/*
Plugin Name: flickrSync
Plugin URI: http://jsmix.com
Description: 同步 Flickr Sets 列表到数据库
Author: Pengzhan.Lee
Version: 1.0
Author URI: http://jsmix.com/
*/

include 'syncSets.php';

add_action( 'admin_menu', 'flickrSync_config_page' );
function flickrSync_config_page() {
	add_submenu_page('plugins.php', 'flickrSync', 'flickrSync', 'manage_options', 'flickrSyncConfig', 'flickrSync_conf');
}

function flickrSync_conf() {
	if ( isset($_POST['submit']) ) {
		if( isset($_POST['action']) && $_POST['action']=='sync' ){
			flickrSyncInit();
		}
	}else{
		getForm();
	}
	
}

function fsLog($msg, $type="", $bold=false){
	if($type != "" && $bold){
		echo "<p class='fs_bold fs_".$type."'>".$msg."</p>";
	}elseif($type != ""){
		echo "<p class='fs_".$type."'>".$msg."</p>";
	}else{
		echo "<p>".$msg."</p>";
	}
	ob_flush();
	flush();  // needed ob_flush
}


function getForm(){
	echo '
	<div class="narrow">
		<form action="" method="post" id="flickrSync_conf" style="margin: auto; width: 400px; ">
			<p class="submit">
				<input type="hidden" name="action" value="sync" />
				<input type="submit" name="submit" value="Synchronize With Flickr" />
			</p>
		</form>
	</div>';
}



function setStyle(){
	echo '	<style>
		#flickrSyncContent{
			height:500px;
			margin-top:20px;
			width:80%;
			overflow-y:scroll;
			padding:10px;
			color:#fff;
			background:black;
		}
		.fs_error{
			color:red;
		}

		.fs_success{
			color:green;
		}

		.fs_warn{
			color:orange;
		}
		
		.fs_bold{
			font-weight:bold;
		}
	</style>
	<script>
		var flickrSyncScroll = setInterval(function(){
			jQuery("#flickrSyncContent").scrollTop(9999);
		},100);
		jQuery(window).bind("load",function(){
			setTimeout(function(){
				clearInterval(flickrSyncScroll);
			},300);
		});
	</script>
	';
}
//add_action("wp_loaded","setStyle");


function flickrSyncInit(){
	setStyle();
	echo '<div id="flickrSyncContent">';
	syncSets();
	echo '<p style="font-family:console;font-size:14px;">[<span style="color:#00ff00;">admin</span><span style="color:#ffff00">@</span><span style="color:#ff00ff">jsmix www.jsmix.com</span> <span style="text-decoration:underline;">/home/admin</span>]<br />$</p>';
	echo '</div>';
	getForm();
}




?>
